package com.test.config;
import com.jfinal.config.*;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.json.JFinalJson;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;
import com.test.interceptor.DemoInterceptor;
import com.test.model._MappingKit;

public class DemoConfig extends JFinalConfig {



    public void configConstant(Constants me) {
        me.setDevMode(true);
        // 开启对 jfinal web 项目组件 Controller、Interceptor、Validator 的注入
        me.setInjectDependency(true);

        // 开启对超类的注入。不开启时可以在超类中通过 Aop.get(...) 进行注入
        me.setInjectSuperClass(true);
        JFinalJson.setModelAndRecordFieldNameToCamelCase();
    }

    public void configRoute(Routes me) {
        // jfinal 4.9.03 版新增了路由扫描功能，不必手动添加路由
        // me.add("/hello", HelloController.class);

        // 使用路由扫描，参数 "demo." 表示只扫描 demo 包及其子包下的路由
        me.scan("com.test.");
    }

    public void configEngine(Engine me) {
        me.setDevMode(true);
        me.setBaseTemplatePath("/view/");
        me.setToClassPathSourceFactory();
    }
    public void configPlugin(Plugins me) {
        DruidPlugin dp = new DruidPlugin("jdbc:mysql://localhost/jfinal-test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8", "root", "");
        me.add(dp);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
        me.add(arp);
//        arp.addMapping("sys_users", User.class);
        _MappingKit.mapping(arp);
        arp.setShowSql(true);
        arp.addSqlTemplate("all.sql");
    }
    public void configInterceptor(Interceptors me) {
        //添加一个全局的拦截器
//        me.addGlobalActionInterceptor(new DemoInterceptor());
    }
    public void configHandler(Handlers me) {
        me.add(new ContextPathHandler("ctx"));
    }
}